<template>
  <div class="mainDiv">
    <el-form ref="websiteForm" label-width="150px" label-position="left">
      <el-form-item label="顶部图" prop="top_image" class="top_image">
        <UploadAvatar v-model="website.top_image" width="960" height="150" tipmsg="必填，请上传1280*150px的jpg.png格式的图片" />
      </el-form-item>
      <el-form-item label="就业联系电话" prop="contact_phone">
        <el-input v-model="website.contact_phone" style="width: 400px;" :maxlength="20" placeholder="选填，少于20个数字和字符" clearable />
      </el-form-item>
      <el-form-item label="微信公众号二维码" prop="wechat_qr" class="qrCode">
        <UploadAvatar v-model="website.wechat_qr" tipmsg="选填，请上传100 * 100px的jpg.png格式的图片" />
      </el-form-item>
      <el-form-item label="微博二维码" prop="weibo_qr" class="qrCode">
        <UploadAvatar v-model="website.weibo_qr" tipmsg="选填，请上传100 * 100px的jpg.png格式的图片" />
      </el-form-item>
      <el-form-item label="就业办邮箱" prop="contact_email">
        <el-input v-model="website.contact_email" style="width: 400px;" placeholder="选填，注意邮箱格式" clearable />
      </el-form-item>
      <el-form-item label="SEO关键词设置" prop="seo_keywords">
        <el-input v-model="website.seo_keywords" style="width: 400px;" :maxlength="30" placeholder="选填，少于30个中文字，关键词之间用','(半角逗号)隔开" clearable />
      </el-form-item>
      <el-form-item>
        <el-button :type="confirmDisabled ? 'info' : 'primary'" :disabled="confirmDisabled" :loading="comfirmLoading" @click="handleConfirmClick">确认</el-button>
        <!-- <el-button>预览</el-button> -->
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { getWebsite, editWebsite } from '../../api/informationNetwork'
export default {
  components: {
    UploadAvatar: () => import('./Upload')
  },
  data() {
    return {
      website: {},
      confirmDisabled: false,
      comfirmLoading: false
    }
  },
  created() {
  },
  mounted() {
    this.getWebsiteMsg()
  },
  methods: {
    // 获取网站信息
    getWebsiteMsg() {
      getWebsite().then(res => {
        this.website = res
      })
    },
    handleConfirmClick() {
      if (this.website.top_image === '') {
        this.$message({
          type: 'error',
          message: '顶部图片未添加！'
        })
      } else {
        this.comfirmLoading = true
        editWebsite(this.website).then(res => {
          this.$message({
            type: 'success',
            message: '保存成功！'
          })
        }).catch(err => {
          console.log(err)
        }).finally(() => {
          this.comfirmLoading = false
        })
      }
    }
  }
}
</script>

<style lang="scss" scoped>
  $defaultColor: #0A2145;
  .mainDiv {
    padding: 30px;
  }
  .el-input__inner {
    color: $defaultColor;
    font-size: 14px;
  }
  .el-form--label-left .el-form-item__label { color: $defaultColor; }

  .el-radio-button__orig-radio:checked+.el-radio-button__inner {
    border-radius: 8px;
    background-color: #0C66FF;
    border-color: #0C66FF;
    box-shadow: -1px 0 0 0 #0C66FF;
  }
  .el-radio-button__inner {
    border: none;
    background: transparent;
    padding: 7px 17px;
  }
  .el-radio-button:first-child .el-radio-button__inner {
    border-left: none;
  }
  .el-radio-group {
    border: 1px solid #F1F1F5;
    border-radius: 8px;
  }
  .el-button:focus, .el-button:hover {
    color: #0C66FF;
    border-color: #0C66FF;
    background-color: #fff;
  }
  .el-button--primary {
    color: #FFF;
    background-color: #0C66FF;
    border-color: #0C66FF;
  }
  .el-button--small {
    border-radius: 8px;
  }
  .el-button--primary:hover {
    color: #fff;
    background-color: #0951CC;
    border-color: #0951CC;
  }
</style>
